import 'package:flutter/material.dart';
import './styleManager.dart';
/*
    todo Row当中 左右对齐如何简单实现 ??
*/
Widget buildItem1(BuildContext context,int index,[int state=1]){
  if (state== 1) {//待评价
     return new Container(
            child: new Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                getPicture(),
                new Expanded(child:getDescribeText(state),),
                getEvaluateButton(),//待评价
              ],
            ),
       );
  } else if (state== 0){//已评价
   return new Container(
            child: new Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                getPicture(),
                new Expanded(child:getDescribeText(state),),
              ],
            ),
       );
  }     
}
Widget buildItem2(BuildContext context,int index){
       return new Container(
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                getTitle(),
                getReview(),//获取评价
                textContainer(),
                getbuildItem1(context, index),
                new Divider(color: Colors.black38),
                getBottom(),
              ],
            ),
       );
       
}
// 获取图片部分
Widget getPicture(){
   return new Container(
      padding: styleManager.padding_picture,
      child:  new Container(
        child:new Image.network('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1554871283449&di=5c614d8e9d077bf5b98c2994908dba6f&imgtype=0&src=http%3A%2F%2Fimg.jdzj.com%2FUserDocument%2F2017a%2Felian5%2FPicture%2F2017621113329.jpg'),
        width:120.0,
        height:90.0,
      ),
   );
}
// 获取描述部分
Widget getDescribeText([int state ]){
  if(state == 1){
    return new Column(
      crossAxisAlignment: CrossAxisAlignment.start,//左对齐
      children: <Widget>[
        new Text('商品名称',style: styleManager.order_black),
        new Text('商品属性',style: styleManager.order_grey),
        new Text('评价可得50积分',style: styleManager.order_grey),
      ],
    );
  }else if(state == 0){
    return new Column(
      crossAxisAlignment: CrossAxisAlignment.start,//左对齐
      children: <Widget>[
        new Text('商品名称',style: styleManager.order_black),
        new Text('商品属性',style: styleManager.order_grey),
        new Text('已好评，共获得50积分',style: styleManager.order_grey),
      ],
    );
  } 
}
// 获取按钮部分
Widget getEvaluateButton(){
  return new Container(
    padding: styleManager.padding_button,
    child:new RaisedButton(
      onPressed: (){},
      color: Colors.green[400],
      child: new Text('发布评价',
        style: TextStyle(
          fontSize: 14.0,
          color: Colors.white,
        ),
      ),
    ),
  );
}
//获取ListView Item的头部分
Widget getTitle(){
   return new Container(
      padding: const EdgeInsets.all(20.0),//此部分四周间隔一定距离
      child:  new Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          new IconButton(icon: Icon(Icons.account_circle,size: 40.0,), onPressed: () {}),
          
          new Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                    padding: const EdgeInsets.only(bottom: 8.0),//与下面文本间隔一定距离
                    child:Text('Windir',style: styleManager.order_big_black),
                  ),
                  Text('学生/深圳',style: styleManager.order_black),
                ],
              ),
          ),
          new IconButton(icon: Icon(Icons.more_horiz), onPressed: () {}),
        ],
      ),
   );
}
//获取评价中间部分
Widget getReview(){
  return Container(
    padding: const EdgeInsets.fromLTRB(5, 0, 5, 0),
    child:new Row(
      children: <Widget>[
        new Container(
          child:new Image.network('http://hbimg.b0.upaiyun.com/bdaca9a07e1a8947c00c2f826ebf848750927aa24963-cATwbg_fw658'),
          width:120.0,
          height:90.0,
        ),
        new Container(
          child:new Image.network('http://hbimg.b0.upaiyun.com/bdaca9a07e1a8947c00c2f826ebf848750927aa24963-cATwbg_fw658'),
          width:120.0,
          height:90.0,
        ),
        new Container(
          child:new Image.network('http://hbimg.b0.upaiyun.com/bdaca9a07e1a8947c00c2f826ebf848750927aa24963-cATwbg_fw658'),
          width:120.0,
          height:90.0,
        ),
      ],
    ),
  );
}
//评价文本部分
Widget textContainer (){
  return Container(
    padding: const EdgeInsets.fromLTRB(32, 0, 32, 0),
    //文本块一定是用'''来引用起来
    child: Text(
      '''
      拿来看也没看就洗了，发现有些不对劲，吊牌都没有，洗的时候还泡沫，细看领口有一处缝补的痕迹虽然是特价买的...
      ''',
    ),
  );
}
// 获取评价商品信息
Widget getbuildItem1(context, index){
   return new Container(
      padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
      child:new Card(
        child:buildItem1(context, index,0),
        color: Colors.grey[200],
      ),
   );
}
//获取评价底部部分
Widget getBottom(){
  return new Container(
    padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
    child:  new Row(
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        new Expanded(
            flex:2,
            child: new Text("一周前",style: styleManager.order_black)),
        new IconButton(icon: Icon(Icons.thumb_up), onPressed: () {}),
        new Text('1000',style: styleManager.order_grey),
        new IconButton(icon: Icon(Icons.forum), onPressed: () {}),
        new Text('100',style: styleManager.order_grey),
      ],
    ),
  );
}
